using System;
using System.Collections.Generic;

namespace GameCore
{
    [Serializable]
    public class AssetBundleInfo
    {
        public string Name { get; set; }
        [Newtonsoft_X.Json.JsonIgnore] public string PackageName => assetPackage.Name;
        public string MD5 { get; set; }
        public long FileSize { get; set; }

        internal AssetPackage assetPackage;

        [Newtonsoft_X.Json.JsonIgnore] public string AssetBundlePath => $"{Global.Config.AssetBundlePath}/{PackageName}/{Name}";

        public AssetBundleInfo() { }

        public AssetBundleInfo(string name, string md5, long fileSize)
        {
            Name = name;
            MD5 = md5;
            FileSize = fileSize;
        }

        public List<AssetInfo> GetAssetInfos()
        {
            var assetInfos = new List<AssetInfo>();
            foreach (var assetInfo in assetPackage.AssetInfos)
            {
                if (assetInfo.AssetBundleName == Name)
                    assetInfos.Add(assetInfo);
            }
            return assetInfos;
        }

        public override string ToString()
        {
            return Name; //必须是名称, 这里有逻辑判断
        }
    }
}